package com.ipzoe.common.retrofit.request;

import com.google.common.collect.Lists;
import lombok.Data;

import java.util.List;

/**
 * LeanCloud请求-会话对象
 * <p>
 * Created 2018/01/19.
 *
 * @author pfzhang
 */
@Data
public class Conversation {

    /** 会话名称 */
    private String name;

    /** 成员ClientID集合 */
    private List<String> m;

    /** 若为true,则为创建聊天室 */
    private Boolean tr;

    /** 若为true,则为系统会话 */
    private Boolean sys;

    /**
     * 创建聊天室
     *
     * @param name 聊天室名称
     * @return 会话对象
     */
    public static Conversation createChatRoom(String name) {
        Conversation conversation = new Conversation();
        conversation.setName(name);
        conversation.setTr(Boolean.TRUE);

        return conversation;
    }

    /**
     * 创建双人会话
     *
     * @param sendId    发送人ID
     * @param receiveId 接收人ID
     * @return 会话对象
     */
    public static Conversation createConversation(Long sendId, Long receiveId) {
        Conversation conversation = new Conversation();
        conversation.setName(sendId + "和" + receiveId + "的会话");

        List<String> m = Lists.newArrayList();
        m.add(sendId.toString());
        m.add(receiveId.toString());

        conversation.setM(m);

        return conversation;
    }

    /**
     * 创建多人会话
     *
     * @param name         会话名称
     * @param memberIdList 成员ID集合
     * @return 会话对象
     */
    public static Conversation createGroup(String name, List<String> memberIdList) {
        Conversation conversation = new Conversation();
        conversation.setName(name);
        conversation.setM(memberIdList);

        return conversation;
    }
}
